<template>

  <el-container class="home-container">
    <!-- 头部区 -->
    <el-header>
      <div class="div1">
        <img src="../assets/heima.png" alt="">
        <span>APP珠宝后台管理系统</span>
      </div>
      <div class="head-sculpture">
        <el-avatar :src="headUrl"></el-avatar>
        <span>{{username}}</span>
      </div>
      <!-- <el-button type="info" @click="logout">退出</el-button> -->
    </el-header>
    <!-- 页面主体区 -->
    <el-container>
      <!-- 侧边栏菜单区 -->
      <el-aside :width="isCollapse ? '64px' :'200px'">

        <div class="toggle-button" @click="toggleCollapse">|||</div>

        <el-menu background-color="#333744" text-color="#fff" active-text-color="#409eff" unique-opened :collapse="isCollapse" :collapse-transition="false" router :default-active="activePath">
          <!-- 一级菜单 -->
          <el-submenu :index="item.id+ '' " v-for="item in menulist" :key="item.id">
            <!-- 一级菜单的模板区 -->
            <template slot="title">
              <!-- 图标 -->
              <i :class="iconObj[item.id]"></i>
              <!-- 文本 -->
              <span>{{item.authName}}</span>
            </template>
            <!-- 二级菜单 -->
            <el-menu-item :index="subItem.path" v-for="subItem in item.children" @click="saveNavStatr(subItem.path)" :disabled="subItem.authName=='管理员列表'?adminmenu:false">
              <template slot="title">
                <!-- 图标 -->
                <i class="el-icon-s-operation"></i>
                <!-- 文本 -->
                <span>{{subItem.authName}}</span>
              </template>
            </el-menu-item>
          </el-submenu>
          </el-submenu>

        </el-menu>
      </el-aside>
      <!-- 右侧内容主体 -->
      <el-main>
        <!-- 路由占位符 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>

</template>

<script>
export default {
  //   created(){
  //       this.getMenuList()

  //   },
  data() {
    return {
      //头像链接
      headUrl: "",
      //用户名称
      username: "",
      //左侧菜单数据
      menulist: [
        {
          id: 1,
          authName: "用户管理",
          children: [
            { id: "1-1", authName: "用户列表", path: "/user" },
            { id: "1-2", authName: "管理员列表", path: "/admin" },
            { id: "1-3", authName: "客户类型列表", path: "/usertype" },
          ],
        },
        {
          id: 2,
          authName: "订单管理",
          children: [{ id: "2-1", authName: "订单列表", path: "/orders" }],
        },
      ],
      iconObj: {
        1: "el-icon-s-custom",
        2: "el-icon-s-goods",
      },
      //是否折叠
      isCollapse: false,
      //被激活的链接地址
      activePath: "",
      //管理员菜单是否禁用
      adminmenu: false,
    };
  },
  created() {
    // this.jurisdiction();
    //this.getMenuList();
    //判断是否有管理员菜单权限
    let userCheckFlag = window.sessionStorage.getItem("userCheckFlag");
    if (userCheckFlag != 1) {
      this.adminmenu = true;
    }

    this.activePath = window.sessionStorage.getItem("activePath");
    this.headUrl = window.sessionStorage.getItem("userFaceLink");
    //console.log(this.headUrl);
    this.username = window.sessionStorage.getItem("userName");
  },
  methods: {
    //退出按钮，主要使用清空token的方法
    logout() {
      window.sessionStorage.clear();
      this.$router.push("/login");
    },
    // //获取所有菜单
    // async getMenuList(){
    //     const {data:res}=await this.$http.get('menus')
    //     console.log(res)
    // }

    //点击按钮切换菜单的折叠与展开
    toggleCollapse() {
      this.isCollapse = !this.isCollapse;
    },
    //储存链接的Index
    saveNavStatr(activePath) {
      console.log(this.$route.path);
      window.sessionStorage.setItem("activePath", activePath);
      this.activePath = activePath;
    },
  },
};
</script>

<style  scoped>
.home-container {
  height: 100%;
}
.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  color: #fff;
  font-size: 20px;
}
.div1 {
  display: flex;
  align-items: center;
}
span {
  margin-left: 15px;
}
.el-aside {
  background-color: #333744;
}
.el-menu {
  border-right: none;
}
.el-main {
  background-color: #eaedf1;
}
.toggle-button {
  background-color: #4a5064;
  font-size: 10px;
  line-height: 24px;
  color: #fff;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
}
.head-sculpture {
  display: flex;
  align-items: center;
  font-size: 12px;
}
</style>